/*
 Copyright 2008 Jason E. Smith Licensed under the Apache License, Version 2.0 (the "License"); 
 You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 */

/*
	ensure("controls::SWFBridge", function(){
	    new SWFBridge({
	        onready : function(){
	            var r = this.flex.create("flash.net.URLRequest");
	                r.setUrl("http://api.flickr.com/services/rest/");
	            var l = this.flex.create("flash.net.URLLoader");
	                l.addEventListener("complete", function(event){
	                    console.log(event.getTarget().getData())
	                });
	                l.load(r);
	        }
	    })
	});
*/


new Class("controls::SWFBridge", {
    inherits: controls.View,

    model: {
		src : "/javascripts/application/controls/SWFBridge/swf/SWFBridge.swf"
	},
	
	preInitialize : function(){
		var args = arguments;
		var model = (args[0] || this.model || {});
		this.addEvent("onFABridgeInitialized", function(){
			this.onready.call(this,null)
		}.bind(this))
		
		this.addEvent("onViewLoaded", function() {
			this.beforeInitialize.apply(this, args);
            (this.initialize) ? this.initialize.apply(this, args) : this;
            this.afterInitialize.apply(this, args);
		}.bind(this));
		
		setTimeout(function(){
			this.bindmodel(model,this.bindview.bind(this));
		}.bind(this),10); 
		return this;
    },
	
	
    initialize : function(){
		console.log(this.element);
		document.body.appendChild(this.element);
		$(this.element).setStyle({width:"1px", height:"1px", position:"absolute", top:"-2000px", left:"-2000px"});
		
		FABridge.addInitializationCallback( "flex", function(){
			this.flex = FABridge.flex;
			this.triggerEvent("onFABridgeInitialized");
		}.bind(this)); 
		swfobject.registerObject(this.firstChild(), "9.0.0", "expressInstall.swf");
		return this;
    },	

	html:
	'<div>\
		<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="1" height="1" id="myid" name="myid">\
			<param name="movie" value="{src}" />\
			<param name="allowscriptaccess" value="always" />\
			<!--[if !IE]>-->\
			<object type="application/x-shockwave-flash" data="{src}" width="444" height="444">\
				<param name="allowscriptaccess" value="always" />\
			<!--<![endif]-->\
				<a href="http://www.adobe.com/go/getflashplayer">\
					<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />\
				</a>\
			<!--[if !IE]>-->\
			</object>\
			<!--<![endif]-->\
		</object>\
	</div>'
});

/*new Class("com::ClassLoader", {
	inherits : controls.SWFBridge,
	
	setUrl : function(url){
		var r = this.flex.create("flash.net.URLRequest");
		this.url = url||"http://api.flickr.com/services/rest/";
		r.setUrl(this.url);
		this.request = r;
	},
	
	load : function(){
		var l = this.flex.create("flash.net.URLLoader");
        l.addEventListener("complete", function(event){
            console.log(event.getTarget().getData())
        });
        l.load(this.request);
	}
});*/


